const db = wx.cloud.database();
const app = getApp();
Page({
  data: {
    flag:0,
    shows: false,
    value:'10'
  },
  onLoad: function (options) {
    var that = this;
    console.log(options);
    that.setData({
      area: options.area,
      geneal: options.agent
    })
    if(options.page){
        that.setData({
            page:options.page
        })
    }
      that.startAnimation();  
      var that=this;
      var phone = wx.getStorageSync('phone')
      if (phone) {
        wx.request({ //发送请求
          url: "https://zg99.offcn.com/index/kanjia/updateuser/?actid=42656&callback=?",
          data: {
              phone: phone,
          }, //接收参数
          success(res) { //返回
              var jsonStr = res.data;
              jsonStr = jsonStr.replace("(", "");
              jsonStr = jsonStr.replace(")", "");
              if (typeof jsonStr != 'object') {
                  jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
                  var theJson = JSON.parse(jsonStr);
              };
              console.log(theJson)
              console.log(theJson.users)
              console.log(theJson.users.zhongjianglv)
              if(theJson.users.biaoji==1){
                that.setData({
                  flag:1
                }) 
              }
              if(theJson.users.zhongjianglv=='undefined'||theJson.users.zhongjianglv=='NaN'||theJson.users.zhongjianglv=='null')
              {
                that.setData({
                  numt:10,
                  value:10
                }) 
               
              }
              else{
                that.setData({
                  numt: theJson.users.zhongjianglv,
                  value:theJson.users.zhongjianglv
                }) 
              }
          }
      })
        wx.request({ //发送请求
          url: 'https://zg99.offcn.com/index/kanjia/getxzlist?actid=42656&callback=?', //接收url
          data: {
            phone: phone
          }, //接收参数
          success(res) {
            var jsonStr = res.data;
            jsonStr = jsonStr.replace("(", "");
            jsonStr = jsonStr.replace(")", "");
            if (typeof jsonStr != 'object') {
              jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
              var theJson = JSON.parse(jsonStr);
            }
            console.log(theJson)
            if (theJson.status == 1) {
              var valuetwo=that.data.value;
              console.log(valuetwo)
              console.log(theJson.lists.length)
              const numbertwo = Number(theJson.lists.length)+Number(1);
              const numberthree=numbertwo*Number(10);
              console.log(numbertwo)
              console.log(numberthree)
              if(theJson.lists.length<=7){
                that.setData({
                  fx: theJson.lists.length,
                  numt: numberthree
                })
              }
              else{
                that.setData({
                  numt: 85
                })
              }
              that.setData({
                fx: theJson.lists.length,
                numt: numberthree
              })
            } 
            else {
              that.setData({
                fx: 0,
                numt: 10
              })
            }
            console.log(that.data.numt)
              wx.request({ //发送请求
                url: "https://zg99.offcn.com/index/kanjia/updateuser/?actid=42656&callback=?",
                data: {
                    phone: phone,
                    zhongjianglv:that.data.numt,
                }, //接收参数
                success(res) { //返回
                    var jsonStr = res.data;
                    jsonStr = jsonStr.replace("(", "");
                    jsonStr = jsonStr.replace(")", "");
                    if (typeof jsonStr != 'object') {
                        jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
                        var theJson = JSON.parse(jsonStr);
                    };
                    console.log(theJson)
                    that.setData({
                      value:that.data.numt
                    })
                }
            })
            }
          //   wx.request({ //发送请求
          //     url: "https://zg99.offcn.com/index/kanjia/updateuser/?actid=42656&callback=?",
          //     data: {
          //         phone: phone,
          //         zhongjianglv:that.data.num,
          //     }, //接收参数
          //     success(res) { //返回
          //         var jsonStr = res.data;
          //         jsonStr = jsonStr.replace("(", "");
          //         jsonStr = jsonStr.replace(")", "");
          //         if (typeof jsonStr != 'object') {
          //             jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          //             var theJson = JSON.parse(jsonStr);
          //         };
          //         console.log(theJson)
          //         that.setData({
          //           value:that.data.numt
          //         })
          //     }
          // })
          
        })
        

      }
  },
  startAnimation(){
    const {wrapWidth,contentWidth} = this.data;
    let duration = contentWidth / 20 * 200; //每次滚动的时间
 
    let timer = null;
    timer&&clearTimeout(timer);
    //设置滚动内容在右侧的初始位置
    this.setData({
      animationData:wx.createAnimation({duration: 0}).translateX(wrapWidth).step().export()
    });
    //设置滚动内容最终的位置
    setTimeout(()=>{
      this.setData({
        animationData:wx.createAnimation({duration: duration}).translateX(-contentWidth).step().export()
      });
    },20)
          // // 滚动一次完成后开始下一次的滚动
            timer = setTimeout(()=>{
              this.startAnimation();

            },duration+1000000)

  },
  initAnimation(){
    wx.nextTick(() => {
      //获取外部容器和滚动内容的宽度
      const query = wx.createSelectorQuery();
      query.select('#content').boundingClientRect(rect=>{
        // console.log(rect)
        this.data.wrapWidth = parseInt(rect.width);
      }).exec();
      query.select('#notice-txt').boundingClientRect(rect=>{
        this.data.contentWidth = parseInt(rect.width);
      }).exec();
    })
  },
  quxiao(){
    var that = this;
    that.setData({
      shows:false
    })
  },
  toAdd(){
    var that = this;
    that.setData({
      shows:true
    })
  },
  // toShare(){

  // },
  kaijiang(){
    wx.navigateTo({
      url: '../zhongjiang/zhongjiang'
    })
  },
  toGongzhonghao(){
    var phone = wx.getStorageSync('phone')
    var that=this;
    wx.request({ //发送请求
      url: "https://zg99.offcn.com/index/kanjia/updateuser/?actid=42656&callback=?",
      data: {
          phone: phone,
          biaoji:1
      }, //接收参数
      success(res) { //返回
          var jsonStr = res.data;
          jsonStr = jsonStr.replace("(", "");
          jsonStr = jsonStr.replace(")", "");
          if (typeof jsonStr != 'object') {
              jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
              var theJson = JSON.parse(jsonStr);
          };
          console.log(theJson)
      }
  })
    if(that.data.flag==1){
      that.setData({
        value:that.data.numt
      }) 
    } 
    else{
      const number = Number(that.data.numt)+Number(10);
      that.setData({
        value:number
      }) 
    }
    wx.navigateTo({
      url: '../gzh/gzh'
    })

    // console.log(that.data.num)
    console.log(that.data.value)
    var phone = wx.getStorageSync('phone')
    wx.request({ //发送请求
      url: "https://zg99.offcn.com/index/kanjia/updateuser/?actid=42656&callback=?",
      data: {
          phone: phone,
          zhongjianglv:that.data.value,
      }, //接收参数
      success(res) { //返回
          var jsonStr = res.data;
          jsonStr = jsonStr.replace("(", "");
          jsonStr = jsonStr.replace(")", "");
          if (typeof jsonStr != 'object') {
              jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
              var theJson = JSON.parse(jsonStr);
          };
          console.log(theJson)
      }
  })
  },
    // 分享
    onShareAppMessage: function () {
      // var that=this
      var title = '抽奖';
      var phone = wx.getStorageSync('phone')
      var area = wx.getStorageSync('area')
      var geneal = wx.getStorageSync('geneal')
      var page = wx.getStorageSync('page')
      // var cover_img = '/images/share/share.jpg';
      return {
        title: title,
        path: '/pages/jiningchoujiang/zhuli/zhuli?yqphone=' + phone + '&area=' + area + '&agent=' +geneal + '&page=' + page,
        imageUrl: '',
        success: function (res) {
          wx.showToast({
            title: '分享成功！',
          })
         }
      }
    },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.initAnimation();
  },

})